home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: actuary@nando.net (Bill McCarthy)
- Newsgroups: comp.lang.c
- Subject: Re: command line argument help
- Date: 27 Jan 1996 21:15:32 GMT
- Organization: News & Observer Public Access
- Message-ID: <4ee4lk$fac@castle.nando.net>
- References: <4edfth$ok@muss.CIS.McMaster.CA>
- Reply-To: actuary@nando.net (Bill McCarthy)
- NNTP-Posting-Host: grail803.nando.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <4edfth$ok@muss.CIS.McMaster.CA>, shadowfax writes:
- >to all the c gods out there:
- >
- >i am not having too much success with command line arguments. i am
- >trying to make a simple sumation executable for dos. i am using borland
- >c++ v3.1. what i want as the end result is the user just types:
- >
- >c:\> sum 6 3
- >
- >and the executable would output an answer of 9. the following is my program:
- >
- >
- >#include <stdio.h>
- >#include <stdlib.h>
- >
- >int main(char *argv[])
-
- main takes no or two arguments. Replace above with:
-
- int main( int argc, char *argv[] )
-
- >{
- > int iSum = 0;
- >
- Now check that user typed both parameters:
-
- if ( argc != 3 )
- {
- fprintf(stderr,"Usage: sum a b; where a & b are ints.\n");
- exit( EXIT_FAILURE );
- }
-
- > iSum = atoi(argv[1]) + atoi(argv[2]);
- > printf("\nthe answer is %d", iSum);
- >
- > return(0);
- >}
- >
- >when i compile and run, it always outputs an anser of 0. can anyone tell
- >me what's wrong?
- >
- >sf
- >
- >
-
-
-
- Bill McCarthy
- actuary@nando.net
- Wendell, NC USA
-
-